package com.micro.client;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

@FeignClient(name = "user-service", fallback = UserServiceClientFallback.class)
public interface UserServiceClient {
    
    @GetMapping("/api/users")
    UserDTO getUserByUsername(@RequestParam("username") String username);
    
    @GetMapping("/api/users/{userId}")
    UserDTO getUserById(@PathVariable("userId") Long userId);
    
    /**
     * 根据身份证号获取乘客信息
     */
    @GetMapping("/api/passengers/search")
    PassengerDTO getPassengerByIdCard(@RequestParam("idCardNumber") String idCardNumber);
    
    /**
     * 用户消费（扣款）
     */
    @PostMapping("/api/users/{userId}/deduct")
    boolean consume(@PathVariable("userId") Long userId, @RequestParam("amount") BigDecimal amount);

    /**
     * 用户充值
     */
    @PostMapping("/api/users/{username}/recharge")
    boolean recharge(@PathVariable("username") String username, @RequestParam("amount") BigDecimal amount);
    
    public static class UserDTO {
        private Long userId;
        private String username;
        private String email;
        private String phone;
        private BigDecimal balance;
        
        // 构造函数
        public UserDTO() {}
        
        // Getter和Setter方法
        public Long getUserId() {
            return userId;
        }
        
        public void setUserId(Long userId) {
            this.userId = userId;
        }
        
        public String getUsername() {
            return username;
        }
        
        public void setUsername(String username) {
            this.username = username;
        }
        
        public String getEmail() {
            return email;
        }
        
        public void setEmail(String email) {
            this.email = email;
        }
        
        public String getPhone() {
            return phone;
        }
        
        public void setPhone(String phone) {
            this.phone = phone;
        }

        public BigDecimal getBalance() {
            return balance;
        }

        public void setBalance(BigDecimal balance) {
            this.balance = balance;
        }
    }
    
    public static class PassengerDTO {
        private Long passengerId;
        private Long userId;
        private String passengerName;
        private String idCardNumber;
        private Integer passengerType;
        private Integer gender;
        private String birthDate;
        private String phoneNumber;
        private Boolean active;
        
        // 构造函数
        public PassengerDTO() {}
        
        // Getter和Setter方法
        public Long getPassengerId() {
            return passengerId;
        }
        
        public void setPassengerId(Long passengerId) {
            this.passengerId = passengerId;
        }
        
        public Long getUserId() {
            return userId;
        }
        
        public void setUserId(Long userId) {
            this.userId = userId;
        }
        
        public String getPassengerName() {
            return passengerName;
        }
        
        public void setPassengerName(String passengerName) {
            this.passengerName = passengerName;
        }
        
        public String getIdCardNumber() {
            return idCardNumber;
        }
        
        public void setIdCardNumber(String idCardNumber) {
            this.idCardNumber = idCardNumber;
        }
        
        public Integer getPassengerType() {
            return passengerType;
        }
        
        public void setPassengerType(Integer passengerType) {
            this.passengerType = passengerType;
        }
        
        public Integer getGender() {
            return gender;
        }
        
        public void setGender(Integer gender) {
            this.gender = gender;
        }
        
        public String getBirthDate() {
            return birthDate;
        }
        
        public void setBirthDate(String birthDate) {
            this.birthDate = birthDate;
        }
        
        public String getPhoneNumber() {
            return phoneNumber;
        }
        
        public void setPhoneNumber(String phoneNumber) {
            this.phoneNumber = phoneNumber;
        }
        
        public Boolean getActive() {
            return active;
        }
        
        public void setActive(Boolean active) {
            this.active = active;
        }
    }
}
